<%-- 
    Document   : phanquyen
    Created on : Oct 7, 2013, 4:22:58 AM
    Author     : Administrator
--%>

<%@page import="Controler.DangNhap"%>
<%@page import="java.util.logging.Level"%>
<%@page import="java.util.logging.Logger"%>
<%@page import="java.io.IOException"%>
<%@page import="Model.Pojo.Nhanvien"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
    Nhanvien nhanvien = (Nhanvien) session.getAttribute("NHAN_VIEN_DANG_NHAP");
    if (nhanvien != null)
    {
        String url = request.getServletPath();

        List<String> Customer = new ArrayList<String>();
        Customer.add("/danh-sach-khach-hang.htm");
        Customer.add("/danh-sach-khach-hang.jsp");
        Customer.add("/them-khach-hang.htm");
        Customer.add("/them-khach-hang.jsp");
        Customer.add("/tim-kiem-khach-hang.htm");
        Customer.add("/cap-nhat-thong-tin-khach-hang.htm");

        List<String> Merchandise = new ArrayList<String>();
        Merchandise.add("/danh-sach-san-pham.htm");
        Merchandise.add("/danh-sach-san-pham.jsp");
        Merchandise.add("/them-san-pham.htm");
        Merchandise.add("/them-san-pham.jsp");
        Merchandise.add("/tim-kiem-san-pham.htm");
        Merchandise.add("/cap-nhat-san-pham.htm");

        Merchandise.add("/danh-sach-danh-muc.htm");
        Merchandise.add("/danh-sach-danh-muc.jsp");
        Merchandise.add("/them-danh-muc.htm");
        Merchandise.add("/them-danh-muc.jsp");
        Merchandise.add("/tim-kiem-danh-muc.htm");
        Merchandise.add("/update-danh-muc.htm");
        Merchandise.add("/delete-danh-muc.htm");

        List<String> Accountant = new ArrayList<String>();
        Accountant.add("/danh-sach-don-hang.htm");
        Accountant.add("/danh-sach-don-hang.jsp");
        Accountant.add("/chi-tiet-don-hang.htm");
        Accountant.add("/chi-tiet-don-hang.jsp");
        Accountant.add("/tim-kiem-don-hang.htm");

        switch (nhanvien.getLoainhanvien().getId())
        {
            case 1:
                try
                {
                    if (!Customer.contains(url))
                    {
                        response.sendRedirect("danh-sach-khach-hang.htm");
                    }
                }
                catch (IOException ex)
                {
                    Logger.getLogger(DangNhap.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;

            case 2://Merchandise
                try
                {
                    if (!Merchandise.contains(url))
                    {
                        response.sendRedirect("danh-sach-san-pham.htm");
                    }
                }
                catch (IOException ex)
                {
                    Logger.getLogger(DangNhap.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;

            case 3://Accountant
                try
                {
                    if (!Accountant.contains(url))
                    {
                        response.sendRedirect("danh-sach-don-hang.htm");
                    }
                }
                catch (IOException ex)
                {
                    Logger.getLogger(DangNhap.class.getName()).log(Level.SEVERE, null, ex);
                }
                break;

            case 4://System Admin
                break;
        }
    }
    else
    {
        response.sendRedirect("dang-nhap.htm");
    }
%>